from flask import request

from core.cpucheck import CpuCheck
from core.cpuregist import CpuRegist
from core.vip import Vip
from tools import md5
from tools.gethardware import GethardWare


def cpucheck():
    """
    获取cpu激活情况
    :return: cpu激活情况
    """
    cpu = GethardWare().get_cpuidOrSerialNumber();
    print(cpu)
    cpuCheck = CpuCheck()
    ret = cpuCheck.cpuCheck(cpu)

    return ret


def cpuRegist(**kwargs):
    """
    cpu激活
    :param name: 账号
    :param password: 密码
    :param isUsername: 是否记住账号 默认N
    :param isPassword: 是否记住密码 默认N
    :return: 激活信息
    """
    requestJson = request.get_json(True)
    print(requestJson)
    name = requestJson["name"];
    password = requestJson["password"]
    isUsername = requestJson["isUsername"];
    isPassword = requestJson["isPassword"]

    if len(password) != 32:
        password = md5.genearteMD5(password)
    cpu = GethardWare().get_cpuidOrSerialNumber()
    cpuRegist = CpuRegist()
    ret = cpuRegist.cpuRegist(cpu, name, password, isUsername, isPassword)

    return ret
